import React, { Component } from 'react'
import TodoFooter from './components/TodoFooter'
import TodoHeader from './components/TodoHeader'
import TodoMain from './components/TodoMain'
import request from './utils/request'

export default class App extends Component {
  state = {
    list: [],
  }
  componentDidMount() {
    this.getList()
  }
  getList = async () => {
    // 请求数据
    // const { data: list } = await request.get('/')
    const { data: list } = await request('/')
    this.setState({ list })
  }
  render() {
    const { list } = this.state
    return (
      <section className='todoapp'>
        <TodoHeader getList={this.getList} />
        <TodoMain list={list} getList={this.getList} />
        <TodoFooter />
      </section>
    )
  }
}
